import logging

from fastapi import APIRouter, Depends

from like.schema_base import PageInationResult
from like.http_base import unified_resp
from .schemas import (
    MedicalOperationClassificationVersion30ListIn, MedicalOperationClassificationVersion30ExportIn, MedicalOperationClassificationVersion30DetailIn, MedicalOperationClassificationVersion30AddIn, 
    MedicalOperationClassificationVersion30EditIn, MedicalOperationClassificationVersion30DelIn, MedicalOperationClassificationVersion30Out)
from .service import IMedicalOperationClassificationVersion30Service, MedicalOperationClassificationVersion30Service

logger = logging.getLogger(__name__)

router = APIRouter(prefix='/operation')


@router.get('/list', response_model=PageInationResult[MedicalOperationClassificationVersion30Out])
@unified_resp
async def operation_list(
        list_in: MedicalOperationClassificationVersion30ListIn = Depends(),
        medical_operation_classification_version30_service: IMedicalOperationClassificationVersion30Service = Depends(MedicalOperationClassificationVersion30Service.instance)):
    """用于存储手术操作分类国家临床版3.0信息的列表"""
    result = await medical_operation_classification_version30_service.list(list_in)
    # result.file_name = "用于存储手术操作分类国家临床版3.0信息的"
    return result

@router.get('/export', response_model=bytes)
@unified_resp
async def operation_export(export_in: MedicalOperationClassificationVersion30ExportIn = Depends(), MedicalOperationClassificationVersion30_service: IMedicalOperationClassificationVersion30Service = Depends(MedicalOperationClassificationVersion30Service.instance)):
    return await MedicalOperationClassificationVersion30_service.export_excel(export_in)


@router.get('/detail')
@unified_resp
async def operation_detail(
        detail_in: MedicalOperationClassificationVersion30DetailIn = Depends(),
        medical_operation_classification_version30_service: IMedicalOperationClassificationVersion30Service = Depends(MedicalOperationClassificationVersion30Service.instance)):
    """用于存储手术操作分类国家临床版3.0信息的详情"""
    return await medical_operation_classification_version30_service.detail(detail_in.id)


@router.post('/add')
@unified_resp
async def operation_add(
        add_in: MedicalOperationClassificationVersion30AddIn,
        medical_operation_classification_version30_service: IMedicalOperationClassificationVersion30Service = Depends(MedicalOperationClassificationVersion30Service.instance)):
    """用于存储手术操作分类国家临床版3.0信息的新增"""
    return await medical_operation_classification_version30_service.add(add_in)


@router.post('/edit')
@unified_resp
async def operation_edit(
        edit_in: MedicalOperationClassificationVersion30EditIn,
        medical_operation_classification_version30_service: IMedicalOperationClassificationVersion30Service = Depends(MedicalOperationClassificationVersion30Service.instance)):
    """用于存储手术操作分类国家临床版3.0信息的编辑"""
    return await medical_operation_classification_version30_service.edit(edit_in)


@router.post('/del')
@unified_resp
async def operation_del(
        del_in: MedicalOperationClassificationVersion30DelIn,
        medical_operation_classification_version30_service: IMedicalOperationClassificationVersion30Service = Depends(MedicalOperationClassificationVersion30Service.instance)):
    """用于存储手术操作分类国家临床版3.0信息的删除"""
    return await medical_operation_classification_version30_service.delete(del_in.id)
